<template>
  <div class="headerBar">
    <div class="backHome" @click="goBack()">
      <svg-icon class="backIcon" icon-class="back"></svg-icon>
    </div>
    <div class="user" @click="quitShow = !quitShow">
      <svg-icon class="userIcon" icon-class="user"></svg-icon>
      <div v-if="quitShow" class="quit">
        <span @click="logout">注销登录</span>
        <span @click="changeTheme">切换主题</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'headerBar',
  data() {
    return {
      quitShow: false,
    }
  },
  methods: {
    goBack() {
      this.$router.push('/')
    },
    logout() {
      this.$store
        .dispatch('user/logout')
        .then(() => {
          this.$router.push({ path: '/login' })
        })
        .catch(() => {})
    },
    changeTheme() {
      this.$router.push('/theme/index')
    },
  },
}
</script>

<style lang="scss" scoped>
.headerBar {
  height: $headerHeight;
  @include background_color('mainColor_5');
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  .backHome {
    position: absolute;
    right: 100px;
    top: 50%;
    transform: translateY(-50%);
    .backIcon {
      cursor: pointer;
      width: 40px;
      height: 40px;
      @include fill_svg('subColorThree');
    }
  }
  .user {
    cursor: pointer;
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    img {
      width: 60px;
      height: 60px;
    }
    .userIcon {
      width: 60px;
      height: 60px;
      @include fill_svg('subColorThree');
    }
    .quit {
      width: 100px;
      position: absolute;
      bottom: -100px;
      right: 0px;
      @include background_color('subColorThree');
      border-radius: 5px;
      display: flex;
      flex-direction: column;
      span {
        height: 45px;
        line-height: 45px;
        cursor: pointer;
      }
      span:hover {
        @include font_color('activeColor');
      }
    }
  }
}
</style>
